package course.java.hr;

import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class HrTest
{

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception
	{
		// try
		// {
		// Company comp = new Company("Acme", "12-3456785");
		// Employee emp = new Employee("Joe Black", "467-89-1234");
		// comp.hire(emp);
		//
		// comp.hire(new Employee("Bill Jones", "123-45-6789"),
		// new Employee ("Mary Smith", "555-22-4444"));
		// comp.hire(new Employee ("Beth Price", "888-99-6789"));
		//
		// //duplicates
		// comp.hire(emp);
		// comp.hire(new Employee ("Beth Price", "888-99-6789"));
		//
		//
		// paythem(comp);
		// //paythem(emp);
		// } catch (IllegalArgumentException e)
		// {
		// e.printStackTrace();
		// }
		// catch (Throwable e)
		// {
		// e.printStackTrace();
		// }
		// finally
		// {
		// System.out.println ("Inside finally");
		// }
		//
		Company c = makeCompany("Acme", "11-2222333");
		System.out.println("******************** TOTAL: " + c.pay());
		Employee e = new Employee("Foo FOo", "123-45-1111");

		try (ObjectOutputStream oos = new ObjectOutputStream(
				new BufferedOutputStream(new FileOutputStream(
						"c:/development/test.dat")));)
		{
			oos.writeObject(e);
		}

		ObjectInputStream oin = new ObjectInputStream(new FileInputStream(
				"c:/development/test.dat"));
		Employee ein = (Employee) oin.readObject();

	}

	public static Company makeCompany(String name, String tid)
	{
		Company c = new Company(name, tid);
		for (int i = 0; i < 100; i++)
		{
			String ename = "Emp " + i;
			String ssn = "100-20-33" + i;
			if (i < 10)
				ssn = ssn + "0";
			c.hire(new Employee(ename, ssn));
		}

		return c;
	}

	public static void paythem(TaxableEntity te)
	{
		te.pay();
	}

}
